package com.mt.roll.wms.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mt.roll.core.api.Assert;
import com.mt.roll.core.base.BaseService;
import com.mt.roll.core.dal.entity.CarTaskExecutionInfo;
import com.mt.roll.core.dal.entity.CarTaskExecutionInfoHis;
import com.mt.roll.core.dal.service.CarTaskExecutionInfoHisServiceBiz;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.mapper.CarTaskExecutionInfoHisVoMapper;
import com.mt.roll.wms.params.CarTaskExecutionInfoHisQueryParam;
import com.mt.roll.wms.service.CarTaskExecutionInfoHisService;
import com.mt.roll.wms.vo.CarTaskExecutionInfoHisVo;
import com.mt.roll.wms.vo.CarTaskExecutionInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther why
 * @date 2021/9/29 15:20
 */
@Service
@Transactional
public class CarTaskExecutionInfoHisServiceImpl extends BaseService implements CarTaskExecutionInfoHisService {

    @Autowired
    private CarTaskExecutionInfoHisVoMapper carTaskExecutionInfoHisVoMapper;

    @Autowired
    private CarTaskExecutionInfoHisServiceBiz carTaskExecutionInfoHisServiceBiz;

    @Override
    public R<PageVo<CarTaskExecutionInfoHisVo>> pageByTerm(CarTaskExecutionInfoHisQueryParam carTaskExecutionInfoHisQueryParam) {
        Page<CarTaskExecutionInfoHisVo> page = new Page<>(carTaskExecutionInfoHisQueryParam.getCurrent(),carTaskExecutionInfoHisQueryParam.getSize());
        IPage<CarTaskExecutionInfoHisVo> iPage = carTaskExecutionInfoHisVoMapper.pageByTerm(page, carTaskExecutionInfoHisQueryParam);
        return successful(new PageVo<>(iPage,CarTaskExecutionInfoHisVo.class));
    }

    @Override
    public R<CarTaskExecutionInfoHisVo> get(IdParam idParam) {
        CarTaskExecutionInfoHis carTaskExecutionInfoHis = carTaskExecutionInfoHisServiceBiz.getById(idParam.getId());
        Assert.notNull("历史任务详情不存在", carTaskExecutionInfoHis);
        CarTaskExecutionInfoHisVo carTaskExecutionInfoHisVo = carTaskExecutionInfoHisVoMapper.getById(idParam.getId());
        return successful(carTaskExecutionInfoHisVo);
    }
}
